IF(NOT CHIBIOS_ROOT)
    SET(CHIBIOS_ROOT /usr/src/chibios)
    MESSAGE(STATUS "No CHIBIOS_ROOT specified, using default: ${CHIBIOS_ROOT}")
ENDIF()

IF(ChibiOS_FIND_VERSION_MAJOR EQUAL 2)
  MESSAGE(FATAL_ERROR "ChibiOS v2.x.x is not supported. Use older version of stm32-cmake")
ELSEIF((NOT ChibiOS_FIND_VERSION_MAJOR) OR (ChibiOS_FIND_VERSION_MAJOR EQUAL 3))
  INCLUDE(ChibiOS3)
ENDIF()

LIST(REMOVE_DUPLICATES ChibiOS_INCLUDE_DIRS)
LIST(REMOVE_DUPLICATES ChibiOS_SOURCES)

INCLUDE(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(ChibiOS DEFAULT_MSG ChibiOS_SOURCES ChibiOS_INCLUDE_DIRS ChibiOS_LINKER_SCRIPT)